<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>公司管理</title>
    <link rel="stylesheet" type="text/css" href="../css/jquery/jquery-ui-1.8.23.custom.css"
          media="screen"/>
    <link rel="stylesheet" type="text/css" href="../css/validata/validationEngine.jquery.css"
          media="screen"/>
    <jsp:include page="../../head.jsp"/>
    <style type="text/css">
        .td_right {
            text-align: right;
        }
    </style>
    <script>
        var contentHtml = "";
        var editor;

        $(document).ready(function () {
            //初始化表单验证引擎
            $("#companyForm").validationEngine("attach", {
                //消息位置
                promptPosition: "bottomRight",
                scroll: false
            });
            //初始化ajaxForm参数
            var options = {
                //提交方式
                type: "POST",
                //提交数据格式
                dataType: "json",
                //在提交之前做的操作
                beforeSubmit: function () {
                    return $("#companyForm").validationEngine("validate");
                },
                //成功后做的操作
                success: function (responseText, statusText, xhr, $form) {
                    alert(responseText.msg);
                    location.href = "company-main";
                }
            };
            $('#companyForm').ajaxForm(options);
        });
        function submitTheForm() {
            $("#companyForm").submit();
        }

        function check(type) {
            $.post("dropdown-companyType", null, function (data) {
                var options = "";
                var result = data;
                if (result != null && result != "") {
                    if (type == null || type == "") {
                        for (var i = 0; i < result.length; i++) {
                            var array = result[i];
                            options =
                                    options + "<option value='" + array[1] + "'>" + array[0]
                                    + "</option>";
                        }
                    } else {
                        for (var i = 0; i < result.length; i++) {
                            var array = result[i];
                            if (type == array[1]) {
                                options =
                                        options + "<option value='" + array[1]
                                        + "' selected='selected'>" + array[0] + "</option>";
                            } else {
                                options =
                                        options + "<option value='" + array[1] + "'>" + array[0]
                                        + "</option>";
                            }
                        }
                    }
                }
                $("#company_type").append(options);
            });
        }

    </script>
</head>
<body>
<%=htmlData%>
<form name="example" id="companyForm" method="post" action="company-saveOrUpdateCompany">
    <div class="ui-widget">
        <table class="ui-widget-content">
            <tr>
                <td class="td_right">公司名称</td>
                <td><input class="validate[required]" type="text" id="company_title" name="name"
                           value="${company.name}" style="width: 482px;"/>*
                </td>
                <td class="td_right">公司类型</td>
                <td>
                    <select id="company_type" name="type">
                        <script>check('${company.type}')</script>
                    </select>

                <%-- <input class="validate[required]" type="text" id="company_type" name="company.type" value="${company.name}" style="width: 482px;"/>*</td>
             --%></tr>
            <tr>
                <td class="td_right">公司电话</td>
                <td><input type="text" name="phone" value="${company.phone}"/></td>
                <td class="td_right">传真</td>
                <td><input type="text" name="fax" value="${company.fax}"/></td>
            </tr>
            <tr>
                <td class="td_right">公司联系人</td>
                <td><input type="text" name="contactor" value="${company.contactor}"/></td>
                <td class="td_right">联系人电话</td>
                <td><input type="text" name="mobile" value="${company.mobile}"/></td>
            </tr>
            <tr>
                <td class="td_right">公司地址</td>
                <td colspan="3"><input type="text" name="address" value="${company.address}"
                                       style="width: 482px;"/></td>
            </tr>
            <tr>
                <td class="td_right">备注</td>
                <td colspan="3"><textarea name="remarks"
                                          style="width: 482px;height: 51px;">${company.remarks}</textarea>
                </td>
            </tr>
            <tr>
                <td class="td_right">是否开通数据接口</td>
                <td colspan="3">
                    <c:choose>
                        <c:when test="${company.isSignWS eq '1'}">
                            <input TYPE="radio" name="isSignWS" value="1" checked="checked" />开通
                            <input TYPE="radio" name="isSignWS" value="0"/>不开通
                        </c:when>
                        <c:otherwise>
                            <input TYPE="radio" name="isSignWS" value="1"/>开通
                            <input TYPE="radio" name="isSignWS" value="0" checked="checked"/>不开通
                        </c:otherwise>
                    </c:choose>

                </td>
            </tr>
            <tr>
                <td colspan="4" align="center" class="bts">
                    <input type="button" onclick="submitTheForm()" name="btn" value="应用存盘"/>
                    <input type="button" onclick="javascript:history.back();" name="btn"
                           value="返回"/>
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" name="id" value="${company.id}"/>
    <input type="hidden" name="validate" value="${company.validate}"/>
    <input type="hidden" name="isabled" value="${company.isabled}"/>
    <input type="hidden" name="state" value="${company.state}"/>
</form>
</body>
</html>
